package com.paisheng.justlife;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.alibaba.fastjson.JSON;
import com.paisheng.justlife.bean.Waste;
import com.paisheng.justlife.utils.DeviceInfoUtils;
import com.paisheng.justlife.utils.SharedPreferencesHelper;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.paisheng.justlife", appContext.getPackageName());
    }

    @Test
    public void test1(){
        Context appContext = InstrumentationRegistry.getTargetContext();
        SharedPreferencesHelper spfh = new SharedPreferencesHelper(appContext,"CAST_MESSAGE");
        List<Waste> lw = new ArrayList<>();
        for (int i = 0; i <15; i++) {
            Waste waste = new Waste();
            waste.setName("塑料"+i);
            waste.setQuantity("重量"+i);
            waste.setResultPrice("总额"+i);
            lw.add(waste);

        }
        String s = JSON.toJSONString(lw);
        spfh.put("13012341234",s);
    }   
    @Test
    public void test2(){
        Context appContext = InstrumentationRegistry.getTargetContext();
        String imei = DeviceInfoUtils.getMacAddress(appContext);
        SharedPreferencesHelper spfh = new SharedPreferencesHelper(appContext,"CAST_MESSAGE");
//        String preference = (String) spfh.getSharedPreference(imei, String.class);
//        List<Waste> wasteList = JSON.parseArray(preference, Waste.class);
//        System.out.println(wasteList.size());
//        System.out.println(wasteList);
        spfh.clear();
    }
}
